package com.example.lishop.controller

import com.example.lishop.base.MyResponse
import com.example.lishop.entity.BBusinessEntity
import com.example.lishop.entity.bean.BaseListBean
import com.example.lishop.service.impl.BusinessServiceImpl
import com.example.lishop.util.SnowflakeUtil
import com.example.lishop.vo.BusinessDetailVo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*

/**
 * Created on 2021/3/14 18:28
 * @author shuguo
 * 商家
 */
@Api(value = "/Business", tags = arrayOf("商家接口"))
@RestController
@RequestMapping("/business")
class BusinessCtl {

    @Autowired
    lateinit var service:BusinessServiceImpl

    @Autowired
    lateinit var productCtl: ProductCtl

    @ApiOperation(value = "添加商家")
    @PostMapping(value = ["/add"])
    fun add(@RequestBody bean:BBusinessEntity) : MyResponse<BBusinessEntity> {
        bean.depId = ""+SnowflakeUtil.instance.nextId(1)
        return MyResponse(200, "添加成功", service.add(bean))
    }

    @ApiOperation(value = "修改商家")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody @Validated bean:BBusinessEntity) : MyResponse<BBusinessEntity> {
        service.update(bean)
        return MyResponse(200, "修改成功", detail(bean).data)
    }

    @ApiOperation(value = "商家列表")
    @PostMapping(value = ["/list"])
    fun list(@RequestBody @Validated bean: BaseListBean) : MyResponse<Page<BBusinessEntity>> {
        return MyResponse(200, "请求列表成功", service.list(bean.page, bean.size))
    }

    @ApiOperation(value = "删除商家")
    @PostMapping(value = ["/del"])
    fun del(@RequestBody @Validated bean:BBusinessEntity) : MyResponse<Unit> {
        return MyResponse(200, "删除成功", service.del(bean))
    }

    @ApiOperation(value = "查询商家")
    @PostMapping(value = ["/detail"])
    fun detail(@RequestBody @Validated bean:BBusinessEntity) : MyResponse<BBusinessEntity> {
        return MyResponse(200, "查找成功", service.detail(bean))
    }

    @ApiOperation(value = "查询商家详情，所有数据")
    @PostMapping(value = ["/detailAll"])
    fun detailAll(@RequestBody @Validated bean:BBusinessEntity) : MyResponse<BusinessDetailVo> {
        return MyResponse(200, "查找成功", service.detailAll(bean))
    }
}